package dao

import (
	log "github.com/sirupsen/logrus"
	"simulationFulu/models"
)

//插入数据
func ProOrderAdd(order *models.ProOrder) int64{
	affected, err := x.Insert(order)
	checkErr(err)
	return affected
}

//改
func ProOrderModify(id int, order *models.ProOrder) bool {
	affected, err := x.Id(id).Cols(
		"CardDeadline",
		"CardPwd",
		"CardNumber").Update(order)
	checkErr(err)
	if affected == 0 {
		return false
	}
	return true
}

//删
func ProOrderRemove(id int) bool{
	order := new(models.ProOrder)
	affected, err:=x.Id(id).Delete(order)
	checkErr(err)
	if affected == 0 {
		return false
	}
	return true
}

//查
func ProOrderGet(id int64) *models.ProOrder {
	order := &models.ProOrder{OrderId: id}
	is, _ := x.Get(order)
	if !is {
		log.Warn("搜索结果不存在!")
		return nil
	}
	return order
}

// 通过订单号查找
func ProOrderByCustomerNo(customerNo string) *models.ProOrder {
	order:=&models.ProOrder{}
	has,err:=x.Where("CustomerOrderNo=?",customerNo).Get(order)
	if !has{
		return nil
	}
	checkErr(err)
	return order
}